<template>
    <div class="orderpage">
        <van-nav-bar title="确认订单">
            <!-- <template #left>
			    <van-icon name="arrow-left" size="18" color="black" @click="backproduct"/>
			  </template> -->
            <!-- <template #right>
			    <van-icon name="share-o" size="18" color="black"/>
			  </template> -->
        </van-nav-bar>
        <van-cell :title="item.shopname" icon="shop-o" :to="{ name: 'shopindex' }" />
        <van-card num="1" price="2.00" :desc="item.description" :title="item.title">
            <template #thumb>
                <van-image width="90" height="90" :src="item.cover" />
            </template>
            <template #price>
                <span style="color: #aaa">￥{{ item.price }}</span>
            </template>
            <template #footer>
                <span>需付款：</span><span style="color: red; font-size: 15px">{{ item.price }}</span>
            </template>
        </van-card>
        <div class="mt-10" style="height: 5px; background: #eee" />
        <xjcoupon :info_id="id" @click="$refs.coupon.showList = true" ref="coupon"></xjcoupon>
        <div style="height: 5px; background: #eee" />
        <!-- <van-cell title="留言" value="选填,建议和商家沟通后再填写" style="font-size: 12px;"/> -->
        <div style="position: absolute; bottom: 0; height: 30px; background: #eee"></div>
        <div class="fixorder">
            <span class="ml-10" style="font-size: 14px">合计：</span>
            <span style="color: red; font-size: 12px">￥</span>
            <span style="color: red; font-size: 19px">{{ pricearr[0] }}</span>
            <span style="color: red; font-size: 14px">{{ pricearr[1] }}</span>
            <van-button
                type="warning"
                class="fr"
                style="border-radius: 15px; height: 30px; margin-top: 10px; margin-right: 10px"
                @click="submitOrder"
                >提交订单</van-button
            >
        </div>
    </div>
</template>

<script>
import xjcoupon from '@/components/frontshop/xjcoupon.vue';
export default {
    components: {
        xjcoupon
    },
    data() {
        return {
            pricearr: [],
            id: '',
            item: '',
            randcode: '',
            jian_price: 0,
            ucp_id: 0
        };
    },
    methods: {
        //添加支付订单
        async submitOrder() {
            let id = this.$route.query.id;
            //let ordernumber=order_number();
            let res = await this.$frontaxios.post(this.$front.addOrder, { id, ucp_id: this.ucp_id, randcode: this.randcode });
            if (res.code == 1 || res.code == 0) {
                this.$router.push({ name: 'pay', query: { ordernumber: res.data.ordernumber, id, randcode: this.randcode } }); //创建新订单成功
            } else if (res.code == 2) {
                this.$notify({ type: 'success', message: '你已经购买此商品，无需重复购买' });
            } else {
                this.$toast.fail('创建订单失败');
            }
        },
        backproduct() {
            //this.$router.push({name:'product',query:{id:this.id}});
            this.$router.back();
        },
        async getData() {
            this.id = this.$route.query.id; //单个专栏id
            this.randcode = this.$route.query.randcode;
            let query = {
                id: this.id
            };
            let res = await this.$frontaxios.post(this.$front.getOneColumn, query);
            if (res.code == 1) {
                this.item = res.data;
                if ((res.data.price * 100 - this.jian_price * 100) / 100 > 0) {
                    this.item.price = (res.data.price * 100 - this.jian_price * 100) / 100;
                } else {
                    this.item.price = 0;
                }
                console.log(this.item.price);
            } else {
                console.log('得到单个专栏失败');
            }
            if (this.item.price > 0) {
                let pricearr = this.item.price.toString().split('.');
                this.pricearr[0] = pricearr[0] + '.';
                this.pricearr[1] = pricearr[1] == undefined ? '00' : pricearr[1];
            } else if (this.item.price == 0) {
                this.pricearr[0] = 0 + '.';
                this.pricearr[1] = '00';
            }
        }
    },
    created() {
        this.getData();
    }
};
</script>

<style lang="scss" scoped>
.orderpage {
    height: 100vh;
    background-color: #eee;
    overflow: scroll;
    .fixorder {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        height: 50px;
        background-color: #fafafa;
        line-height: 50px;
    }
    .van-card {
        background-color: white;
    }
}
</style>
